package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created by mz on 26/7/17.
 *
 */
@Data
public class ImmunizationSubRecord implements Serializable{

    private static final ObjectMapper objectMapper= JsonMapper.nonEmptyMapper().getMapper();


    private static final long serialVersionUID = -8333423286207589053L;

    /**
     *
     */
    private Long id;

    /**
     * 关联的主表的id
     */
    private Long vaccineId;

    /**
     * 栏舍号id
     */
    private Long stableId;

    /**
     *'栏舍号',
     */
    private String  stableNumber;

    /**
     *养殖区域 10：繁殖区, 20：保育区, 30：育肥区',
     */
    private Integer area;

    /**
     * 记录时间
     */
    private Date date;
    /**
     *免疫类型'
     */
    private Integer type;
    /**
     *其他免疫类型
     */
    private String otherType;
    /**
     * 疫苗名称code
     */
    private Integer vaccineCode;
    /**
     * 疫苗名称name
     */
    private String vaccineName;
    /**
     *免疫天数
     */
    private Integer days;
    /**
     *免疫 期次
     */
    private Integer times;
    /**
     *免疫数量
     */
    private Integer quantity;
    /**
     *免疫方式
     */
    private Integer method;

    /**
     * 免疫用药剂量单位
     */
    private Integer  drugUnit;

    /**
     *免疫用药量
     */
    private Float drugQuantity;

    /**
     *免疫生产厂商
     */
    @JsonIgnore
    private String manufacturerPhoto;
    /**
     * 免疫生产厂商---不存入数据库
     */
    private Map<String,Map<String,String>> manufacturer;
    /**
     * 免疫编号
     */
    @JsonIgnore
    private String batchNumber;
    /**
     * 免疫编号---不存入数据库
     */
    private Map<String,Map<String,String>> batch;

    /**
     *'免疫操作人员
     */
    private String  operatorName;

    /**
     * 1：正常，-1：删除'
     */
    private Integer deleteFlag;


    public void setManufacturerPhoto(String manufacturerPhoto){
        this.manufacturerPhoto=manufacturerPhoto;
        if(Strings.isNullOrEmpty(manufacturerPhoto)){
            this.manufacturer= Maps.newHashMap();
        }else {
            try {
                this.manufacturer = objectMapper.readValue(manufacturerPhoto, new TypeReference<Map<String,Map<String,String>>>(){});
            } catch (IOException e) {
                //this is fuck exception
            }
        }
    }
    public void setManufacturer(Map<String,Map<String,String>> manufacturer){
        this.manufacturer=manufacturer;
        if(manufacturer==null ||manufacturer.isEmpty()){
            this.manufacturerPhoto=null;
        }else{
            try{
                this.manufacturerPhoto = objectMapper.writeValueAsString(manufacturer);
            }catch (Exception e){
                //this is fuck exception
            }
        }
    }

    public void setBatchNumber(String batchNumber){
        this.batchNumber = batchNumber;
        if(Strings.isNullOrEmpty(batchNumber)){
            this.batch= Maps.newHashMap();
        } else{
            try {
                this.batch= objectMapper.readValue(batchNumber,new TypeReference<Map<String,Map<String,String>>>() {});
            } catch (IOException e) {
                //this is fuck exception
            }
        }
    }

    public void setBatch(Map<String,Map<String,String>> batch) {
        this.batch = batch;
        if(batch ==null ||batch.isEmpty()){
            this.batchNumber = null;
        }else{
            try {
                this.batchNumber = objectMapper.writeValueAsString(batch);
            } catch (Exception e) {
                //this is fuck exception
            }
        }
    }


    private String number;
    private String breedFactoryName;
}
